




var _oMessages =
{
sNoSelectedAttribute: LOCID_ATTRLST_MUSTSELECT
};





var _oConst =
{

entityId:						"entityId",
attributeId:					"attributeId",
attributeFilter:				"attributeFilter",

sCreateAttributeUrlFormat:		"manageAttribute.aspx?entityId={0}",
sUpdateAttributeUrlFormat:		"manageAttribute.aspx?attributeId={0}&entityId={1}",
sUpdateAction:					"update",
sDeleteAction:					"delete",
iAttributeEditorWidth:			800,
iAttributeEditorHeight:			600
};





var _sEntityId;





function AttributeListJsWindowOnLoad()
{

_sEntityId = gridAttributes.GetParameter(_oConst.entityId);


gridAttributes.OnBeforeFormLoad = onAttributeDblClick;
gridAttributes.SetParameter("disableDblClick", "0");
}
window.attachEvent('onload', AttributeListJsWindowOnLoad);








function dispatchAction(sAttributeOid, sAction)
{
if (sAttributeOid == null)
{
alert(_oMessages.sNoSelectedAttribute);
return;
}


switch (sAction)
{
case _oConst.sDeleteAction:
{
deleteAttributeAction(sAttributeOid);
break;
}

case _oConst.sUpdateAction:
{
updateAttributeAction(sAttributeOid);
break;
}
}
}



function remoteAttributeCommandCallback(oResult)
{
if (oResult.Success &&
oResult.RemoteCommand.Command == _oAttrUtlConst.sDeleteAttributeCommand &&
!IsNull(oResult.ReturnValue) &&
oResult.ReturnValue.Used)
{
showUsage(_oSCUConst.sAttributeMode, oResult.ReturnValue);
}
else
{
gridAttributes.Refresh();
}
return true;
}



function createAttributeAction()
{
var sUrl = formatString(_oConst.sCreateAttributeUrlFormat, _sEntityId);
openStdWin(sUrl, buildWinName(), _oConst.iAttributeEditorWidth, _oConst.iAttributeEditorHeight);
}



function updateAttributeAction(sAttributeOid)
{
var sAttributeId	= getAttributeId(sAttributeOid);
var sUrl			= formatString(_oConst.sUpdateAttributeUrlFormat, sAttributeId,_sEntityId);
openStdWin(sUrl, buildWinName(sAttributeId), _oConst.iAttributeEditorWidth, _oConst.iAttributeEditorHeight);
}



function deleteAttributeAction(sAttributeOid)
{
var sAttributeId = getAttributeId(sAttributeOid);
var bCustomAttribute = isCustomAttribute(sAttributeOid);
deleteAttribute(sAttributeId, bCustomAttribute, remoteAttributeCommandCallback);
}








function onFilterChange()
{
gridAttributes.SetParameter(_oConst.attributeFilter, selFilter.DataValue);
gridAttributes.Refresh();
}



function onAttributeDblClick()
{
updateAttributeAction(event.ObjectID);
event.returnValue = false;
}










function getSelectedAttributeOid()
{
var aRecords = gridAttributes.InnerGrid.SelectedRecords;
return (aRecords.length > 0) ? aRecords[0][0] : null;
}



function isCustomAttribute(sAttributeOid)
{
return sAttributeOid.split(":")[0] == "1";
}



function isCustomizableAttribute(sAttributeOid)
{
return sAttributeOid.split(":")[1] == "1";
}



function getAttributeId(sAttributeOid)
{
return sAttributeOid.split(":")[2];
}
